* Consider a sysem with a server and three external clients
* and each client issues a job at a constant rate lambda. The
* service time of an external job is exactly F time units, and 
* after the server finishes a job, it takes a "vacation" and process
* its local job for exactly G time units.
* Assume that lambda = 1 /min, the service time of an external
* job is F = 2 minutes, and the vacation lasts G = 4 minutes. 
* Find the throughput of the external jobs and the expected 
* response time for each external job.

format 8

bind
n 50
lambda 1
F 2
G 4
uF n/F
uG n/G
end

mrgp vac_queue
3001 - 2101 exp(3*lambda)
2101 - 1201 exp(2*lambda)
1201 - 0301 exp(lambda)
3010 @ 2110 exp(3*lambda)
2110 - 1210 exp(2*lambda)
1210 - 0310 exp(lambda)
3001 @ 3010 Erlang(n,uG)
2101 @ 2110 Erlang(n,uG)
1201 @ 1210 Erlang(n,uG)
0301 @ 0310 Erlang(n,uG)
2110 @ 3001 Erlang(n,uF)
1210 @ 2101 Erlang(n,uF)
0310 @ 1201 Erlang(n,uF)
* Reward function 
reward
3001 val_3001
3010 val_3010
2101 val_2101
2110 val_2110
1201 val_1201
1210 val_1210
0301 val_0301
0310 val_0310
end

* Reward assignment for the throughput of the external jobs
bind
val_3001 3
val_3010 3
val_2101 2
val_2110 2
val_1201 1
val_1210 1
val_0310 0
val_0301 0
end

echo Steady State Probabilities:
expr prob(vac_queue, 3001), prob(vac_queue, 3010)
expr prob(vac_queue, 2101), prob(vac_queue, 2110)
expr prob(vac_queue, 1201), prob(vac_queue, 1210)
expr prob(vac_queue, 0301), prob(vac_queue, 0310)

echo Throughput: of the External Jobs:
expr exrss(vac_queue)

* Reward assignment for the expected queue length
bind 
val_3001 0
val_3010 0
val_2101 1
val_2110 1
val_1201 2
val_1210 2
val_0301 3
val_0310 3
end

* E[Response time]=E[Queue Length]/E[Arrival Rate]
expr exrss(vac_queue)/0.1667906
end




